package com.guanzhi.service.impl;

import com.guanzhi.emnu.AlgorithmMode;
import com.guanzhi.mapper.UserMapper;
import com.guanzhi.mapper.UserMapperPlus;
import com.guanzhi.po.Personnel;
import com.guanzhi.service.UserService;
import com.guanzhi.utils.AesSecurityUtil;
import com.guanzhi.utils.UUIDLong;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * SpringBoot 实战
 * <p> Package: com.guanzhi.service.impl </p>
 * <p> File: UserServiceImpl.java </p>
 * <p> Description:  (用户业务处理)</p>
 * <p> Date: 2024/2/5 18:37</p>
 *
 * @author 观之
 * @version 1.0 （代码版本）
 * @email <a href="mailto:guanzhi55634@aliyun.com">观之</a>（邮箱）
 * @date 2024/2/5 18:37
 * @since jdk17（jdk版本）
 */
@Service
@AllArgsConstructor
public class UserServiceImpl implements UserService {

    private UserMapper userMapper;

    private UserMapperPlus userMapperPlus;

    @Override
    public Personnel findPersonnelById(Long id) {
        return userMapper.findPersonnelById(id);
    }

    @Override
    public Personnel findPersonnelByUsername(String username) {
        return userMapper.findPersonnelByUsername(username);
    }

    @Override
    public void register(String username, String password) {
        Personnel personnel = new Personnel();
        //主键
        personnel.setId(UUIDLong.longUUID());
        //用户名
        personnel.setUsername(username);
        //密码采用AES 加密
        personnel.setPassword(AesSecurityUtil.AES_CBC(password, AlgorithmMode.encrypt.getMode()));
        //创建时间
        personnel.setCreateTime(new Date());
        //修改时间
        personnel.setUpdateTime(new Date());
        //插入
        userMapperPlus.insert(personnel);
    }
}
